package com.sise.wangzhan.myclientcofigure;

import feign.MethodMetadata;
import org.springframework.cloud.openfeign.support.SpringMvcContract;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @Classname MyContract
 * @Description TODO
 * @Date 2020/4/16 13:02
 * @Created by wangzhan
 */
public class MyContract extends SpringMvcContract {

    //处理方法级的注解
    @Override
    protected void processAnnotationOnMethod(MethodMetadata data, Annotation annotation, Method method){
        //调用父类的方法，可以支持@RequestMapping 注解
        super.processAnnotationOnMethod(data,annotation,method);
        //判断是MyUrl注解才运行处理
        if (MyUrl.class.isInstance(annotation)){
            //获取注解实例
            MyUrl myUrl = method.getAnnotation(MyUrl.class);
            //获取配置的Http方法
            String httpMethod = myUrl.method();
            //获取服务的url
            String url = myUrl.url();
            //将值设置到模板中
            data.template().method(httpMethod);
            data.template().append(url);
        }
    }



}
